Ext.define('AmpleHarvest.objects.aqb.search.cAreaNorth',
{
	extend				: 'Ext.form.Panel',
	alias			: 'widget.ampleharvest-objects-aqb-search-careanorth',
	requires			:
	[
			"AmpleHarvest.DATA.Store.cQueryCondition",
//			"AmpleHarvest.objects.search.panel.cControl",
			"AmpleHarvest.objects.aqb.search.cEnhancedSearch",
			"AmpleHarvest.objects.aqb.search.cGeneralSearch"
	],
	title				: 'Enhanced Query Builder',
	iconCls				: 'window-search-builder-icon',
	collapsible			: true,
	split				: true,
	padding				: 5,
	height				: 500,
	region				: "north",
	frame				: true,
	layout				:
	{
		type	: 'vbox',
		align	: 'stretch'
	},

	initComponent		: function()
	{

		this.m_obj_EnhancedSearchWindow = Ext
				.create("AmpleHarvest.objects.aqb.search.cEnhancedSearch",
						{
							json	: this.json
						});
		this.m_obj_GeneralSearch = Ext
				.create("AmpleHarvest.objects.aqb.search.cGeneralSearch");
		this.buttons =
		[
				{
					text	: 'Clear',
					handler	: function()
					{
						this.ownerCt.ownerCt.clearEnhancedQuery();
					}
				},
				{
					text	: 'Save',
					handler	: function()
					{
						m_obj_enhancedSearch
								.fireEvent(
										AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_SAVED_QUERY_ADD,
										this.ownerCt.ownerCt.get_JsonQuery(),
										this.m_str_SourceGUID
								);
					}
				},
				{
					text	: 'Search',
					handler	: function()
					{
						this.ownerCt.ownerCt.do_Search();
					}
				}
		];

		this.callParent();
		
		this.add(this.m_obj_GeneralSearch);
		this.add(this.m_obj_EnhancedSearchWindow);
		
		this.on("afterrender", function()
				{
					// TODO - after render process any sent json data
			
			
//					if (Ext.isObject(g_arr_Requests["json"]))
//					{
//						this.do_Search();
//					}
				});
	},

	clearEnhancedQuery	: function()
	{
		this.m_obj_GeneralSearch.clearField();
		this.m_obj_EnhancedSearchWindow.getStore().getRootNode().removeAll();
	},

	get_JsonQuery		: function()
	{
		return this.ownerCt.get_JsonQuery();
	},

	do_Search			: function()
	{
		this.ownerCt.do_Search();
	},

	get_QueryObject		: function()
	{
		var obj_General = this.m_obj_GeneralSearch.get_QueryObject();
		var obj_Search = this.m_obj_EnhancedSearchWindow.get_QueryObject();

		obj_Search.Query = obj_Search.Query.concat(obj_General.Query);
		return obj_Search;
	}
}
);